#include "process.h"

void process()
{
    char buffer[NUM];
    memset(buffer, 0, sizeof(buffer));
    char lable[4] = { '/','-', '\\', '|'};
    int len = sizeof(lable);

    for (int i = 1;i < (NUM);i++)
    {
        buffer[i - 1] = FILL;
        printf("[%-100s][%d%%]", buffer, i);
        printf("[%c]\r", lable[i % len]);
        fflush(stdout);
        Sleep(100);
    }
    printf("\n");
}

void FlashProcess(double allsize, double newsize)
{
    assert(allsize >= newsize);
    char buffer[NUM];
    memset(buffer, 0, sizeof(buffer));
    char lable[4] = { '/','-', '\\', '|' };
    int lablen = sizeof(lable);
    static int count = 0;
    double d_rate = (newsize / allsize) * 100;
    int i_rate = (int)d_rate;
    memset(buffer, FILL, sizeof(char)* i_rate);
    printf("[%-100s][%0.2ff%%]", buffer, d_rate);
    printf("[%c]\r", lable[count % lablen]);
    fflush(stdout);
    count++;
}
